package cn.biwysh.exam.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.biwysh.exam.biz.ExamBiz;
import cn.biwysh.exam.biz.ZhiShiBiz;
import cn.biwysh.exam.entity.User;

public class Self extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
		String url="WEB-INF/jsp/self.jsp";
		HttpSession session = request.getSession(false);
		User user=null;
		if(session!=null){
			if (session.getAttribute("userqt") != null) {
				user = (User) session.getAttribute("userqt");
				if(user!=null){
					ZhiShiBiz biz=new ZhiShiBiz();
					request.setAttribute("list", biz.GetSelfCate(user.getId()));
					ExamBiz ebiz=new ExamBiz();
					request.setAttribute("scores", ebiz.GetScoreByPage(" and uid="+user.getId(), 1, 10000));
					RequestDispatcher requestDispatcher = request.getRequestDispatcher(url);
					requestDispatcher.forward(request, response);
				}else{
					response.sendRedirect("index.do");
				}
			}else{
				response.sendRedirect("index.do");
			}
		}else{
			response.sendRedirect("index.do");
		}
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
     this.doGet(request, response);
	}

}
